package com.dongrj.framework.core.exception;


import com.dongrj.framework.core.constant.Constant;

/**
 * @author dongrongjun
 * @date 2020/08/04
 */
public class BusinessException extends RuntimeException {

    private Integer code = Constant.Code.FAIL_BIZ;

    private static final long serialVersionUID = 1L;

    public BusinessException(Throwable e) {
        super(getMessage(e), e);
    }

    public BusinessException(String message) {
        super(message);
    }

    public BusinessException(String messageTemplate, Object... params) {
        super(String.format(messageTemplate, params));
    }

    public BusinessException(String message, Throwable throwable) {
        super(message, throwable);
    }

    public BusinessException(String message, Throwable throwable, boolean enableSuppression, boolean writableStackTrace) {
        super(message, throwable, enableSuppression, writableStackTrace);
    }

    public BusinessException(Throwable throwable, String messageTemplate, Object... params) {
        super(String.format(messageTemplate, params), throwable);
    }

    private static String getMessage(Throwable e) {
        if (null == e) {
            return "";
        }
        return String.format("%s: %s", e.getClass().getSimpleName(), e.getMessage());
    }

}
